//
//  BaseSourceViewController.m
//  AnXin100
//
//  Created by Sakura on 2018/11/13.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "BaseSourceViewController.h"
#import "XXPageTabView.h"
#import "XXPageTabItemLable.h"
#import "BaseSourceChildViewController.h"
#import "UIViewController+HBD.h"

@interface BaseSourceViewController ()<XXPageTabViewDelegate>
@property (nonatomic, strong) XXPageTabView *pageTabView;

@end

@implementation BaseSourceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupNavigationItems];
    [self.view addSubview:self.pageTabView];
}

- (void)setupNavigationItems {
    
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    /** title */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"基地溯源";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
}

- (void)backAction:(UIBarButtonItem *)item {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (XXPageTabView *)pageTabView
{
    if (!_pageTabView) {
    
        for (NSInteger i = 0; i < 4; i++) {
            BaseSourceChildViewController *vc = [BaseSourceChildViewController new];
            [self addChildViewController:vc];
        }
        //支持网易云音乐，今日头条，微博等切换栏效果
        _pageTabView = [[XXPageTabView alloc] initWithChildControllers:self.childViewControllers childTitles:@[@"水果", @"蔬菜",@"农产品", @"农技"]];
        _pageTabView.frame = CGRectMake(0, Hn, Wi, Hi-Hn);
        
        _pageTabView.selectedTabIndex = 0;
        _pageTabView.maxNumberOfPageItems = 5;
        _pageTabView.tabSize = CGSizeMake(Wi, 44);
        _pageTabView.tabItemFont = FONT_FOURTEEN;
        
        _pageTabView.unSelectedColor = White(50);
        _pageTabView.selectedColor = COLOR_GREEN;
        
        _pageTabView.tabBackgroundColor = White(250);
        
        //_pageTabView.separatorColor = [[UIColor grayColor] colorWithAlphaComponent:0.4];
        _pageTabView.bodyBounces = NO;
        
        _pageTabView.indicatorWidth = 50;
        _pageTabView.indicatorHeight = 2;
        
        _pageTabView.delegate = self;
        _pageTabView.titleStyle = XXPageTabTitleStyleDefault;
        _pageTabView.indicatorStyle = XXPageTabIndicatorStyleDefault;
        
        UIScrollView *bodyView = [_pageTabView valueForKey:@"bodyView"];
        [bodyView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
    }
    return _pageTabView;
}

- (void)pageTabViewDidEndChange
{
    DLog(@"page = %i", (int)self.pageTabView.selectedTabIndex);
}


@end
